﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frame.Lib.Core.Config;
using Frame.Lib.Core.Register;
using Frame.Lib.Utilities;
using System.Threading;
using Frame.Lib.Core.Log;

namespace Frame.Lib.Core.Cache.SysConfig
{
    public class SysConfigLoader : CacheLoaderBase
    {

        

        public override void LoadData()
        {
            try
            {
                SysConfigContainer container = new SysConfigContainer();

                SysConfigBO cfg = new SysConfigBO();
                List<SysConfigInfo> list = cfg.GetList();

                container.SysConfigs = new Dictionary<string, SysConfigInfo>();

                foreach (SysConfigInfo info in list)
                {
                    container.SysConfigs.Add(info.ID, info);
                }
                if (container.SysConfigs.ContainsKey(ConfigID.reginfo.ToString()))
                {
                    container.RegisterInfo = (RegisterInfo)Serialize.BinaryDeserialize(container.SysConfigs[ConfigID.reginfo.ToString()].Config);
                }
                else
                {
                    container.RegisterInfo = new RegisterInfo();
                }

                LoadComplete(container);
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "load sysconfig cache fail");
            }
        }
    }
}
